|
1
|
|
|
/* |
|
2
|
|
|
* Files_FullTextSearch - Index the content of your files |
|
3
|
|
|
* |
|
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
5
|
|
|
* later. See the COPYING file. |
|
6
|
|
|
* |
|
7
|
|
|
* @author Maxence Lange <[email protected]> |
|
8
|
|
|
* @copyright 2018 |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** global: OCA */ |
|
28
|
|
|
|
|
29
|
|
|
var fullTextSearch = OCA.FullTextSearch.api; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
var elements = { |
|
33
|
|
|
old_files: null, |
|
34
|
|
|
search_result: null, |
|
35
|
|
|
current_dir: '' |
|
36
|
|
|
}; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
var FullTextSearch = function () { |
|
40
|
|
|
this.init(); |
|
41
|
|
|
}; |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
FullTextSearch.prototype = { |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* File actions handler, defaults to OCA.Files.FileActions |
|
48
|
|
|
* @type OCA.Files.FileActions |
|
49
|
|
|
*/ |
|
50
|
|
|
fileActions: null, |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
init: function () { |
|
54
|
|
|
var self = this; |
|
55
|
|
|
|
|
56
|
|
|
elements.old_files = $('#app-content-files'); |
|
57
|
|
|
|
|
58
|
|
|
elements.search_result = $('<div>'); |
|
59
|
|
|
elements.search_result.insertBefore(elements.old_files); |
|
60
|
|
|
|
|
61
|
|
|
fullTextSearch.setResultContainer(elements.search_result); |
|
62
|
|
|
fullTextSearch.setEntryTemplate(self.generateEntryTemplate()); |
|
63
|
|
|
fullTextSearch.setResultHeader(self.generateResultHeader()); |
|
64
|
|
|
// fullTextSearch.setResultFooter(self.generateResultFooter()); |
|
65
|
|
|
|
|
66
|
|
|
fullTextSearch.initFullTextSearch('files', 'files', self); |
|
67
|
|
|
|
|
68
|
|
|
this._initFileActions(); |
|
69
|
|
|
}, |
|
70
|
|
|
|
|
71
|
|
|
_initFileActions: function () { |
|
72
|
|
|
|
|
73
|
|
|
this.fileActions = new OCA.Files.FileActions(); |
|
74
|
|
|
this.fileActions.registerDefaultActions(); |
|
75
|
|
|
this.fileActions.merge(window.FileActions); |
|
76
|
|
|
this.fileActions.merge(OCA.Files.fileActions) |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
this._onActionsUpdated = _.bind(this._onActionsUpdated, this); |
|
|
|
|
|
|
79
|
|
|
OCA.Files.fileActions.on('setDefault.app-files', this._onActionsUpdated); |
|
80
|
|
|
OCA.Files.fileActions.on('registerAction.app-files', this._onActionsUpdated); |
|
81
|
|
|
window.FileActions.on('setDefault.app-files', this._onActionsUpdated); |
|
82
|
|
|
window.FileActions.on('registerAction.app-files', this._onActionsUpdated); |
|
83
|
|
|
|
|
84
|
|
|
// if (this._detailsView) { |
|
85
|
|
|
// this.fileActions.registerAction({ |
|
86
|
|
|
// name: 'Details', |
|
87
|
|
|
// displayName: t('files', 'Details'), |
|
88
|
|
|
// mime: 'all', |
|
89
|
|
|
// order: -50, |
|
90
|
|
|
// iconClass: 'icon-details', |
|
91
|
|
|
// permissions: OC.PERMISSION_NONE, |
|
92
|
|
|
// actionHandler: function (fileName, context) { |
|
93
|
|
|
// self._updateDetailsView(fileName); |
|
94
|
|
|
// } |
|
95
|
|
|
// }); |
|
96
|
|
|
// } |
|
97
|
|
|
}, |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
_onActionsUpdated: function (ev, newAction) { |
|
|
|
|
|
|
101
|
|
|
if (ev.action) { |
|
102
|
|
|
this.fileActions.registerAction(ev.action); |
|
103
|
|
|
} else if (ev.defaultAction) { |
|
104
|
|
|
this.fileActions.setDefault( |
|
105
|
|
|
ev.defaultAction.mime, |
|
106
|
|
|
ev.defaultAction.name |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
}, |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
generateResultHeader: function () { |
|
113
|
|
|
|
|
114
|
|
|
var resultHeader = $('<div>', {class: 'files_header'}); |
|
115
|
|
|
resultHeader.append($('<div>', {class: 'files_div_checkbox'}).html(' ')); |
|
116
|
|
|
resultHeader.append($('<div>', {class: 'files_div_thumb'}).html(' ')); |
|
117
|
|
|
resultHeader.append( |
|
118
|
|
|
$('<div>', {class: 'files_header_div files_div_name'}).text(_('Name'))); |
|
119
|
|
|
resultHeader.append( |
|
120
|
|
|
$('<div>', {class: 'files_header_div files_div_modified'}).text(_('Modified'))); |
|
121
|
|
|
resultHeader.append( |
|
122
|
|
|
$('<div>', {class: 'files_header_div files_div_size'}).text(_('Size'))); |
|
123
|
|
|
|
|
124
|
|
|
return resultHeader; |
|
125
|
|
|
}, |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
generateResultFooter: function () { |
|
129
|
|
|
var resultFooter = $('<div>', {class: 'files_footer'}); |
|
130
|
|
|
|
|
131
|
|
|
return resultFooter; |
|
132
|
|
|
}, |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* |
|
137
|
|
|
* !!! use this in the fulltextsearch app |
|
138
|
|
|
* !!! use this in the fulltextsearch app |
|
139
|
|
|
* !!! use this in the fulltextsearch app |
|
140
|
|
|
*/ |
|
141
|
|
|
generateEntryTemplate: function () { |
|
142
|
|
|
|
|
143
|
|
|
var resultName = $('<div>', {class: 'files_result_file'}); |
|
144
|
|
|
resultName.append($('<div>', { |
|
145
|
|
|
id: 'title', |
|
146
|
|
|
class: 'files_result_title' |
|
147
|
|
|
})); |
|
148
|
|
|
resultName.append($('<div>', { |
|
149
|
|
|
id: 'extract', |
|
150
|
|
|
class: 'files_result_extract' |
|
151
|
|
|
})); |
|
152
|
|
|
|
|
153
|
|
|
var resultEntry = $('<div>', {class: 'files_result'}); |
|
154
|
|
|
resultEntry.append($('<div>', {class: 'files_div_checkbox'})); |
|
155
|
|
|
resultEntry.append($('<div>', {class: 'files_div_thumb files_result_div'})); |
|
156
|
|
|
|
|
157
|
|
|
resultEntry.append($('<div>', {class: 'files_result_div files_div_name'}).append(resultName)); |
|
158
|
|
|
|
|
159
|
|
|
var resultMore = $('<span>', {class: 'icon icon-more'}); |
|
160
|
|
|
|
|
161
|
|
|
// <a class="action action-menu permanent" href="#" data-action="menu" data-original-title="" |
|
162
|
|
|
// title=""> <span class="icon icon-more"></span><span |
|
163
|
|
|
// class="hidden-visually">Actions</span></a> |
|
164
|
|
|
resultEntry.append( |
|
165
|
|
|
$('<div>', {class: 'files_result_div files_result_item files_div_more'}).append(resultMore)); |
|
166
|
|
|
|
|
167
|
|
|
resultEntry.append( |
|
168
|
|
|
$('<div>', {class: 'files_result_div files_result_item files_div_size'})); |
|
169
|
|
|
|
|
170
|
|
|
var resultModified = $('<div>', {class: 'files_result_div files_result_item files_div_modified'}); |
|
171
|
|
|
resultModified.append($('<div>', {id: 'modified'})); |
|
172
|
|
|
resultModified.append($('<div>', {id: 'info'})); |
|
173
|
|
|
resultEntry.append(resultModified); |
|
174
|
|
|
|
|
175
|
|
|
return $('<div>').append(resultEntry); |
|
176
|
|
|
}, |
|
177
|
|
|
|
|
178
|
|
|
|
|
179
|
|
|
onEntryGenerated: function (divEntry, entry) { |
|
180
|
|
|
|
|
181
|
|
|
var divFile = divEntry.find('.files_result'); |
|
182
|
|
|
divFile.attr({ |
|
183
|
|
|
'data-id': entry.id, |
|
184
|
|
|
'data-type': entry.info.type, |
|
185
|
|
|
'data-size': entry.info.size, |
|
186
|
|
|
'data-file': entry.info.file, |
|
187
|
|
|
'data-mime': entry.info.mime, |
|
188
|
|
|
'data-mtime': entry.info.mtime, |
|
189
|
|
|
'data-etag': entry.info.etag, |
|
190
|
|
|
'data-permissions': entry.info.permissions, |
|
191
|
|
|
'data-path': entry.info.path |
|
192
|
|
|
}); |
|
193
|
|
|
|
|
194
|
|
|
var mtime = parseInt(entry.info.mtime, 10) * 1000; |
|
195
|
|
|
var size = OC.Util.humanFileSize(parseInt(entry.info.size, 10), true); |
|
|
|
|
|
|
196
|
|
|
var thumb = '/index.php/core/preview?fileId=' + entry.id + '&x=32&y=32&forceIcon=0&c=' + |
|
197
|
|
|
entry.info.etag; |
|
198
|
|
|
divEntry.find('.files_div_size').text(size); |
|
199
|
|
|
divEntry.find('#modified').text(OC.Util.relativeModifiedDate(mtime)); |
|
200
|
|
|
divEntry.find('.files_div_thumb').css('background-image', 'url("' + thumb + '")'); |
|
201
|
|
|
}, |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
onEntrySelected: function (divEntry, event) { |
|
205
|
|
|
|
|
206
|
|
|
var resultEntry = divEntry.find('.files_result'); |
|
207
|
|
|
this.fileActions.currentFile = resultEntry; |
|
208
|
|
|
|
|
209
|
|
|
var path = resultEntry.attr('data-path'); |
|
210
|
|
|
var filename = resultEntry.attr('data-file'); |
|
211
|
|
|
var mime = resultEntry.attr('data-mime'); |
|
212
|
|
|
var type = resultEntry.attr('data-type'); |
|
213
|
|
|
var permissions = resultEntry.attr('data-permissions'); |
|
214
|
|
|
|
|
215
|
|
|
if (type !== 'file') { |
|
216
|
|
|
return false; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
if (event && (event.ctrlKey || event.which === 2 || event.button === 4)) { |
|
220
|
|
|
return false; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
var action = this.fileActions.getDefault(mime, type, permissions); |
|
224
|
|
|
|
|
225
|
|
|
if (action) { |
|
226
|
|
|
|
|
227
|
|
|
event.preventDefault(); |
|
228
|
|
|
window.FileActions.currentFile = this.fileActions.currentFile; |
|
229
|
|
|
action(filename, { |
|
230
|
|
|
$file: resultEntry, |
|
231
|
|
|
fileList: this, |
|
232
|
|
|
fileActions: this.fileActions, |
|
233
|
|
|
dir: path |
|
234
|
|
|
}); |
|
235
|
|
|
|
|
236
|
|
|
return true; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
return false; |
|
240
|
|
|
// if (event && (event.ctrlKey || event.which === 2 || event.button === 4)) { |
|
241
|
|
|
// window.open('/remote.php/webdav' + path + '/' + filename); |
|
242
|
|
|
// } else { |
|
243
|
|
|
// window.open('/remote.php/webdav' + path + '/' + filename, '_self'); |
|
244
|
|
|
// } |
|
245
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
}, |
|
248
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
getModelForFile: function () { |
|
251
|
|
|
return null; |
|
252
|
|
|
}, |
|
253
|
|
|
|
|
254
|
|
|
|
|
255
|
|
|
changeDirectory: function (targetDir, changeUrl, force, fileId) { |
|
256
|
|
|
var self = this; |
|
257
|
|
|
var currentDir = '/'; |
|
258
|
|
|
targetDir = targetDir || '/'; |
|
259
|
|
|
if (!force && currentDir === targetDir) { |
|
260
|
|
|
return; |
|
261
|
|
|
} |
|
262
|
|
|
this._setCurrentDir(targetDir, changeUrl, fileId); |
|
263
|
|
|
|
|
264
|
|
|
// discard finished uploads list, we'll get it through a regular reload |
|
265
|
|
|
this._uploads = {}; |
|
266
|
|
|
this.reload().then(function (success) { |
|
267
|
|
|
if (!success) { |
|
268
|
|
|
self.changeDirectory(currentDir, true); |
|
269
|
|
|
} |
|
270
|
|
|
}); |
|
271
|
|
|
}, |
|
272
|
|
|
|
|
273
|
|
|
onSearchRequest: function (data) { |
|
274
|
|
|
if (data.options.files_within_dir === '1') { |
|
275
|
|
|
var url = new URL(window.location.href); |
|
|
|
|
|
|
276
|
|
|
data.options.files_within_dir = url.searchParams.get("dir"); |
|
277
|
|
|
} |
|
278
|
|
|
}, |
|
279
|
|
|
|
|
280
|
|
|
|
|
281
|
|
|
onResultDisplayed: function () { |
|
282
|
|
|
elements.old_files.fadeOut(150, function () { |
|
283
|
|
|
elements.search_result.fadeIn(150); |
|
284
|
|
|
}); |
|
285
|
|
|
}, |
|
286
|
|
|
|
|
287
|
|
|
|
|
288
|
|
|
onResultClose: function () { |
|
289
|
|
|
elements.search_result.fadeOut(150, function () { |
|
290
|
|
|
elements.old_files.fadeIn(150); |
|
291
|
|
|
}); |
|
292
|
|
|
}, |
|
293
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
onSearchReset: function () { |
|
296
|
|
|
elements.search_result.fadeOut(150, function () { |
|
297
|
|
|
elements.old_files.fadeIn(150); |
|
298
|
|
|
}); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
}; |
|
302
|
|
|
|
|
303
|
|
|
|
|
304
|
|
|
OCA.Files.FullTextSearch = FullTextSearch; |
|
305
|
|
|
|
|
306
|
|
|
$(document).ready(function () { |
|
307
|
|
|
OCA.Files.FullTextSearch = new FullTextSearch(); |
|
308
|
|
|
}); |
|
309
|
|
|
|
|
310
|
|
|
|
|
311
|
|
|
|
|
312
|
|
|
|
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.
Further Readings: